<?php

namespace App\Models;

use App\Models\Field\TopicField;
use Illuminate\Database\Eloquent\Factories\HasFactory;


/**
 * App\Models\SysTopic
 *
 * @property int $id 自增ID
 * @property string $topic_id 话题ID
 * @property string $user_id 用户ID
 * @property string $description 描述
 * @property string $title 标题
 * @property int $type 话题类型，1用户话题，2运营话题
 * @property int $total 话题内容个数
 * @property int $is_deleted 是否删除，0正常，1删除
 * @property int $created_at 创建时间戳
 * @property int $updated_at 更新时间戳
 * @property int $is_hot 是否被设为热门，0否，1是
 * @property int $is_recommend 是否被设为推荐，0否，1是
 *
 * @method static \Illuminate\Database\Eloquent\Builder|SysTopic newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|SysTopic newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|SysTopic query()
 * @mixin \Eloquent
 */
class SysTopic extends BaseModel
{
    use HasFactory;

    protected $table = "sys_topic_";
    protected $primaryKey = "id";
    protected $keyType = "int";
    public $timestamps = true;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'created_at' => 'timestamp',
        'updated_at' => 'timestamp',
    ];

    /**
     * select columns
     * @var array
     */
    public $fields = [
        'verifyTopic'        => ['title', 'topic_id', 'updated_at', 'is_deleted'],
        'info'               => ['title', 'topic_id', 'updated_at', 'description', 'total', 'is_deleted'],
        'getTopicAll'        => ['title', 'topic_id', 'updated_at', 'is_deleted'],
        'hotTopic'           => ['title', 'topic_id', 'updated_at', 'description', 'is_deleted'],
        'desktopSearchTopic' => ['title', 'topic_id', 'updated_at', 'description', 'is_deleted'],
    ];

    public function commonFormat($scene = TopicField::BASE_INFO): array
    {
        $formats = TopicField::getFormats($scene);
        return TopicField::format($this, $formats);
    }
}
